import 'package:flutter/material.dart';

class Adapt {
  static double screenWidth = 0;
  static double screenHeight = 0;
  static double physicalWidth = 0;
  static double physicalHeight = 0;
  static double dpr = 0;
  static double ratio = 1.0;
  static double statusBarHeight = 0;
  static double bottomHeight = 0;

  // ignore: non_constant_identifier_names
  static void init(BuildContext context, {double UIWidth = 375}) {
    // 1.媒体查询信息
    final mediaQueryData = MediaQuery.of(context);

    // 2.获取宽度、高度、像素比
    screenWidth = mediaQueryData.size.width;
    screenHeight = mediaQueryData.size.height;
    physicalWidth = View.of(context).physicalSize.width;
    physicalHeight = View.of(context).physicalSize.height;
    dpr = View.of(context).devicePixelRatio;

    // 3.获取状态栏的高度
    // 顶部有刘海:47pt 没有刘海的屏幕为20pt
    statusBarHeight = mediaQueryData.padding.top;
    // 底部有刘海:34pt 没有刘海的屏幕0pt
    bottomHeight = mediaQueryData.padding.bottom;
    // 计算最终渲染比例
    ratio = screenWidth / UIWidth;
  }

  static pt(size) {
    return size * Adapt.ratio;
  }
}
